<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page contentType="text/html;charset=UTF-8" language="java"
	isELIgnored="false"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>登录/注册</title>
<link rel="stylesheet" href="${ctxStatic}/AdminLTE-2.3.11/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="${ctxStatic}/AdminLTE-2.3.11/bootstrap/css/bootstrap-theme.min.css">
<link href="${ctxStatic}/css/signin.css" rel="stylesheet">
<link rel="stylesheet" href="${ctxStatic}/css/xcConfirm.css">
<style type="text/css">
</style>
</head>
<body  style="background: #bdd6e1;">
	<div id="v_ginmsg" style="max-width: 150px;margin: 0 auto;">
		<h3><b>MMS</b><small>会员管理系统</small></h3>
	</div>
	<div class="container" style="max-width:360px; background:transparent; background-color:rgba(255,255,255,0.50)"> 
		<form id="logForm" method="post" class="form-signin" οnsubmit="return false;">
			<h4 class="form-signin-heading">请输入账号密码登录</h4>
			<label for="inputEmail" class="sr-only">账号:</label>
        	<input type="text" id="inputName" name="logname" class="form-control" placeholder="账号/手机号" required autofocus>
        	<label for="inputPassword" class="sr-only">密码:</label>
        	<input type="password" id="inputPassword" name="pwd" class="form-control" placeholder="密码" required>
        	<div class="checkbox">
          		<label>
            		<input  type="checkbox" value="remember-me"> 记住密码
          		</label>
        	</div>
        	<button type="button" id="btn_login" class="btn btn-lg btn-primary btn-block" >登录</button>
		</form>
		<div id="v_bottom" style="margin-left: 12px;">
			<span style=" color: #ccc;">忘记密码?<span><a href="#" style="font-size: 12px;">立即找回</a><br>
			<div style="height: 5px;"></div>
			<a href="#" class="text-center" style="font-size: 12px;">注册一个新账号</a>
		</div> 
	</div>
<script src="${ctxStatic}/AdminLTE-2.3.11/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="${ctxStatic}/AdminLTE-2.3.11/bootstrap/js/bootstrap.min.js"></script>
<%-- <script src="${ctxStatic}/js/jquery-1.9.1.js"></script> --%>
<script src="${ctxStatic}/js/xcConfirm.js"></script>
<script type="text/javascript">
(function(){
	$(function(){
		window.alert=function(msg){
			window.wxc.xcConfirm(msg, window.wxc.xcConfirm.typeEnum.info);
		}
       	var cdata=getCookie("login_code");      
        console.log(cdata);
	});
	
	
	$('#btn_login').click(function() {
		var inputName=$("#inputName").val();
		var inputPassword=$("#inputPassword").val();
		if(null==inputName||inputName.length<=0){
			alert("输入用户名不正确!");
			return;
		}
		if(null==inputPassword||inputPassword.length<=0){
			alert("输入密码不正确!");
			return;
		}
		 $.ajax({  
		    type: "POST",  
		    url:'${mainPath}/checklog',
		    data:$('#logForm').serialize(),  
		    async: true,  //false为同步,true为异步
		    success: function(data) {
		    	console.log(data);
		        //接收后台返回的结果  
		        
		        var info=JSON.parse(data);
				if (info.success) {
					//登录成功后添加cookie
					setCookie();
					window.location.href = '${mainPath}/sys';
				} else {
					alert(info.msg);
				}
		    }  
		});		 	
	});
	
	function setCookie(){
		debugger
		var data={
				name : $("#inputName").val(),
				pwd : $("#inputPassword").val(),
				checked : $("input[type='checkbox']").is(':checked')//获取“是否记住密码”复选框	
		}
		  
        //console.log("setCookie方法是否记住密码："+checked);
		var date=new Date();
		if(data.checked){//记住密码
			//设置cookie过期时间
			date.setTime(date.getTime()+60*1000);//只能这么写，60表示60秒钟
			document.cookie = "login_code" + "=" + JSON.stringify(data) + "; expires=" + date;
		}else{
			//删除cookie
			date.setTime(date.getTime()-1);//设置过去的时间表示删除cookie,删除时可以不用设值
			document.cookie = "login_code" + "=; expires=" + date;
		}
	}
	function getCookie(cname){
		var name=cname+"=";
		var ca = document.cookie.split(';');
		  for(var i=0; i<ca.length; i++) 
		  {
		    var c = ca[i].trim();
		    if (c.indexOf(name)==0) return c.substring(name.length,c.length);
		  }
		  return "";
	}
})()			
</script>
</body>
</html>

